package org.ruoyi.aibox.controller;

import java.util.List;

import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.ruoyi.common.idempotent.annotation.RepeatSubmit;
import org.ruoyi.common.log.annotation.Log;
import org.ruoyi.common.web.core.BaseController;
import org.ruoyi.core.page.PageQuery;
import org.ruoyi.common.core.domain.R;
import org.ruoyi.common.core.validate.AddGroup;
import org.ruoyi.common.core.validate.EditGroup;
import org.ruoyi.common.log.enums.BusinessType;
import org.ruoyi.common.excel.utils.ExcelUtil;
import org.ruoyi.aibox.domain.vo.DocAuditResultDetailVo;
import org.ruoyi.aibox.domain.bo.DocAuditResultDetailBo;
import org.ruoyi.aibox.service.IDocAuditResultDetailService;
import org.ruoyi.core.page.TableDataInfo;

/**
 * 文档审核结果明细
 *
 * @author xpeter
 * @date 2025-04-29
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/aibox/auditResultDetail")
public class DocAuditResultDetailController extends BaseController {

    private final IDocAuditResultDetailService docAuditResultDetailService;

    /**
     * 查询文档审核结果明细列表
     */
    @SaCheckPermission("aibox:auditResultDetail:list")
    @GetMapping("/list")
    public TableDataInfo<DocAuditResultDetailVo> list(DocAuditResultDetailBo bo, PageQuery pageQuery) {
        return docAuditResultDetailService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出文档审核结果明细列表
     */
    @SaCheckPermission("aibox:auditResultDetail:export")
    @Log(title = "文档审核结果明细", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(DocAuditResultDetailBo bo, HttpServletResponse response) {
        List<DocAuditResultDetailVo> list = docAuditResultDetailService.queryList(bo);
        ExcelUtil.exportExcel(list, "文档审核结果明细", DocAuditResultDetailVo.class, response);
    }

    /**
     * 获取文档审核结果明细详细信息
     *
     * @param detailId 主键
     */
    @SaCheckPermission("aibox:auditResultDetail:query")
    @GetMapping("/{detailId}")
    public R<DocAuditResultDetailVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long detailId) {
        return R.ok(docAuditResultDetailService.queryById(detailId));
    }

    /**
     * 新增文档审核结果明细
     */
    @SaCheckPermission("aibox:auditResultDetail:add")
    @Log(title = "文档审核结果明细", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody DocAuditResultDetailBo bo) {
        return toAjax(docAuditResultDetailService.insertByBo(bo));
    }

    /**
     * 修改文档审核结果明细
     */
    @SaCheckPermission("aibox:auditResultDetail:edit")
    @Log(title = "文档审核结果明细", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody DocAuditResultDetailBo bo) {
        return toAjax(docAuditResultDetailService.updateByBo(bo));
    }

    /**
     * 删除文档审核结果明细
     *
     * @param detailIds 主键串
     */
    @SaCheckPermission("aibox:auditResultDetail:remove")
    @Log(title = "文档审核结果明细", businessType = BusinessType.DELETE)
    @DeleteMapping("/{detailIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] detailIds) {
        return toAjax(docAuditResultDetailService.deleteWithValidByIds(List.of(detailIds), true));
    }
}
